﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace HCLSMod.NetSocket
{
    public class TCPIPClientCommand: TCPClientSocket
    {
        public event TCPIPSerRecCommand OnRecCommand;
        public TCPIPClientCommand():base()
        {
            this.OnReceive += TCPIPClientCommand_OnReceive;
        }

        private void TCPIPClientCommand_OnReceive(object sender, Socket ClientSocket, ref byte[] RecData)
        {
            TCPIPCommandBase fCommand = TCPIPCommandBase.DeserializeCommand(RecData);
            RecData = null;
            if (fCommand != null)
            {
                if (OnRecCommand != null)
                    OnRecCommand(this, ClientSocket, ref fCommand);
            }
        }

        public TCPIPClientCommand(IPEndPoint HostEndPointInfoX) : base(HostEndPointInfoX)
        {
            this.OnReceive += TCPIPClientCommand_OnReceive;
        }
        
        public int Send(TCPIPCommandBase fCommand)
        {
            return base.Send(fCommand.SerializeCommand());
        }
        
    }
}
